RateLimiter

JS/TS-friendly facade over com.sorinirmies.arrow.resiliencekit.RateLimiter (token bucket).

import { RateLimiter } from "arrow-resilience-kit";

const rl = await RateLimiter.create({ permitsPerSecond: 10, burstCapacity: 20 });
const result = await rl.execute(() => api.request());

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

Current number of available tokens.

Link copied to clipboard
fun <T> execute(block: () -> Promise<T>): Promise<T>

Executes block if a token is available; rejects otherwise.

Link copied to clipboard
fun <T> executeOrFallback(fallback: () -> Promise<T>, block: () -> Promise<T>): Promise<T>

Executes block, falling back to fallback if no token is available.

Link copied to clipboard

Resets the rate limiter to a full bucket and clears statistics.

Link copied to clipboard

Resets statistics counters (not the available-token balance).

Link copied to clipboard

Current statistics snapshot.

Link copied to clipboard
fun tryAcquire(permits: Int): Promise<Boolean>

Tries to acquire permits tokens without executing anything. Resolves true if acquired.

Link copied to clipboard
fun <T> tryExecute(block: () -> Promise<T>): Promise<T?>

Executes block only if a token is immediately available, resolving null otherwise.